<%--@elvariable id="countPage" type="java.lang"--%>
<%--@elvariable id="typeId" type="java.lang"--%>
<%--@elvariable id="searchName" type="java.lang.String"--%>
<%--@elvariable id="courseInfoListSize" type="java.lang"--%>
<%--@elvariable id="typeValues" type="com.genghis.ptas.classify.entity.TypeValues"--%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ page import="com.genghis.ptas.course.entity.CourseInfo" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@include file="../../includes/index.jsp" %>
    <link rel="stylesheet" type="text/css" href="<c:url value="/css/common/global.css"/>"/>
    <link rel="stylesheet" type="text/css"
          href="<c:url value="/js/common/jquery-easyui-1.3.4/themes/bootstrap/easyui.css"/>"/>
    <link rel="stylesheet" type="text/css" href="<c:url value="/js/common/jquery-easyui-1.3.4/themes/icon.css"/>"/>
    <script src="<c:url value="/js/common/jquery-easyui-1.3.4/jquery.easyui.min.js"/>" type="text/javascript"></script>
    <script src="<c:url value="/js/common/jquery-easyui-1.3.4/locale/easyui-lang-zh_CN.js"/>"
            type="text/javascript"></script>
    <script src="<c:url value="/js/common/common.js"/>" type="text/javascript"></script>

    <script type="text/javascript" src="corporate/plugins/back-to-top.js"></script>

    <%
        Boolean isLogin = (Boolean) request.getAttribute("isLogin");
        List<CourseInfo> top = (List<CourseInfo>) request.getAttribute("top");
        List<CourseInfo> courseInfoList = (List<CourseInfo>) request.getAttribute("courseList");
        Map pageMap = (Map) request.getAttribute("pageMap");
    %>
</head>
<body>
<div>
    <form id="course" action="public/courseList?typeId=${typeValues.id}" method="post">
        <div class="title-wrapper">
            <div class="container">
                <div class="container-inner">
                    <h1><span>${typeValues.typeName}</span> ${typeValues.typeValue}
                    </h1>
                    <em>共 ${courseInfoListSize} 条数据</em>
                </div>
            </div>
        </div>
        <div class="container">


            <!-- BEGIN SIDEBAR -->
            <div class="sidebar col-md-3 col-sm-5">
                <div class="sidebar-products clearfix">
                    <h1 style="text-align: center;">
                        排行榜
                    </h1>
                    <hr style="margin-bottom: 50px;">
                    <div id="rank">
                        <% for (int i = 0; i < top.size(); i++) {%>
                        <div class='item'>
                            <a href="javascript:void(0);" onclick="watchCourseInfo('<%=top.get(i).getId()%>')">
                                <img alt="<%=top.get(i).getCourseName()%>" src="<%=top.get(i).getPhotoUrl()%>">
                            </a>

                            <h3>
                                <a href="javascript:void(0);" onclick="watchCourseInfo('<%=top.get(i).getId()%>')">
                                    <%=i + 1%>.<%=top.get(i).getCourseName()%>
                                </a>
                            </h3>

                            <div class="price">
                                <%=top.get(i).getAverageScore()%>
                            </div>
                        </div>

                        <%}%>
                    </div>
                </div>
            </div>
            <!-- END SIDEBAR -->

            <div class="col-md-9 col-sm-7">
                <div class="content-search margin-bottom-20">
                    <div class="row">
                        <div class="col-md-6 col-sm-6">
                            <h1>
                                查询结果
                                <small><em>${searchName}</em></small>
                            </h1>
                        </div>
                        <div class="col-md-6 col-sm-6">
                            <div class="input-group">
                                <input class="form-control" name="searchName" id="searchName" value="${searchName}"
                                       type="text" placeholder="继续查询">
                                <span class="input-group-btn">
                                <a class="btn btn-primary" href="javascript:" onclick="queryCourse()">查询</a>
                                </span>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- BEGIN PRODUCT LIST -->
                <div class="row product-list">
                    <%
                        int beginCount = (Integer) pageMap.get("beginCount");
                        int endCount = (Integer) pageMap.get("endCount");
                        for (int i = beginCount; i < endCount; i++) {
                            CourseInfo courseInfo = courseInfoList.get(i);
                    %>
                    <!-- PRODUCT ITEM START -->
                    <div class="col-md-4 col-sm-6 col-xs-12">
                        <div class="product-item">
                            <div class="pi-img-wrapper">
                                <img src="<%=courseInfo.getPhotoUrl()%>" class="img-responsive"
                                     style="width: 290px;height: 180px"
                                     alt="Berry Lace Dress">

                                <div>
                                    <%if (isLogin) {%>
                                    <a href="javascript:void(0);" onclick='registerCourse(<%=courseInfo.getId()%>)'
                                       class="btn btn-default">注册</a>
                                    <%}%>
                                    <a href="javascript:void(0);" onclick="watchCourseInfo(<%=courseInfo.getId()%>)"
                                       class="btn btn-default">课件信息</a>
                                </div>
                            </div>
                            <h3><a href="javascript:void(0);"
                                   onclick='watchCourseInfo(<%=courseInfo.getId()%>)'><%=courseInfo.getCourseName()%>
                            </a></h3>

                            <div class="pi-price">
                                <%=courseInfo.getAverageScore()%>
                            </div>
                            <a href="javascript:void(0);" onclick='collectionCourse(<%=courseInfo.getId()%>)'
                               class="btn btn-default add2cart">收藏</a>
                        </div>
                    </div>
                    <%}%>
                </div>
            </div>

            <!-- BEGIN PAGINATOR -->
            <div class="row">
                <div class="pull-right items-info">&nbsp;&nbsp;&nbsp;&nbsp;共${countPage}页</div>
                <ul class="pagination pull-right">
                    <li><a href="javascript:void(0);" onclick="skipPageFirst()">&laquo;</a></li>
                    <%
                        int nowPage = (Integer) pageMap.get("page");
                        Integer beginPage = (Integer) pageMap.get("beginPage");
                        Integer endPage = (Integer) pageMap.get("endPage");
                        for (int a = beginPage; a < endPage + 1; a++) {
                    %>
                    <li>
                        <% if (nowPage == a) {%>
                        <span><%=a%></span>
                        <%} else {%>
                        <a href='javascript:void(0);' onclick='skipPage(<%=a%>)'><%=a%>
                        </a>
                        <%}%>
                    </li>
                    <%}%>
                    <li><a href="javascript:void(0);" onclick="skipPageLast()">&raquo;</a></li>
                </ul>

                <input type="hidden" id="page" name="page" value="<%=pageMap.get("page")%>">
                <input type="hidden" id="pageCount" name="pageCount" value="<%=pageMap.get("count")%>">
            </div>
            <!-- END PAGINATOR -->
        </div>
    </form>
</div>

</body>
</html>

<script type="text/javascript">
    jQuery(document).ready(function () {
        App.init();
        App.initBxSlider();
        Index.initLayerSlider();
        App.initImageZoom();
        App.initTouchspin();
        var height = document.documentElement.clientHeight;
        parent.getHeight(height);
    });

    function skipPage(num) {
        $("#page").val(num);
        formSub();
    }
    //第一页
    function skipPageFirst() {
        $("#page").val(1);
        formSub();
    }
    //最后一页
    function skipPageLast() {
        $("#page").val(${countPage});
        formSub();
    }

    function registerCourse(courseId) {
        $.ajax({
            url: basePath + "courseRegister/addCourseRegister",
            async: false,
            data: {
                courseId: courseId,
                totalTime: "0000:00:00.00"
            },
            dataType: "json",
            type: "POST",
            success: function (judge) {
                if (judge) {
                    parent.bootbox.alert("注册成功！");
                } else {
                    parent.bootbox.alert("您已注册可以直接观看！");
                }

            },
            error: function () {
                parent.bootbox.alert("注册失败！");
            }
        })
    }

    function watchCourseInfo(courseId) {
        parent.window.location.href = basePath + "course/courseInfoDo?id=" + courseId;
    }

    function collectionCourse(courseId) {
        $.ajax({
            url: basePath + "courseRegister/collectionCourse",
            async: false,
            data: {
                courseId: courseId
            },
            dataType: "json",
            type: "POST",
            success: function (judge) {
                if (judge) {
                    parent.bootbox.alert("收藏成功！");
                } else {
                    parent.bootbox.alert("您已收藏！");
                }
            },
            error: function () {
                parent.bootbox.alert("请先登录！");
            }
        })
    }

    function queryCourse() {
        location.href = "courseList?typeId=${typeId}&searchName=" + $("#searchName").val();
    }
</script>
